package com.tjbank.cssys.service.config.shiro;

import org.apache.shiro.config.Ini;
import org.apache.shiro.config.Ini.Section;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.FactoryBean;

/**
 * Copyright © 天阳宏业科技股份有限公司 - All Rights Reserved
 *
 * @description: 在此类中可从数据库中读取过滤的权限信息,以动态方式配置.
 * @author: <a href="mailto:guzheng01@tansun.com.cn>Joey Gu</a>
 * @date: 2020-06-08 18:58
 **/
public class FilterChainDefinitionMap implements FactoryBean<Section> {

    private static final Logger log = LoggerFactory.getLogger(FilterChainDefinitionMap.class);

    private String filterChainDefinitions;

    @Override
    public Section getObject() {
        if (log.isDebugEnabled()) {
            log.debug(">>>读取filterChainDefinitions的权限过滤配置:"+filterChainDefinitions);
        }
        Ini ini = new Ini();

        // 加载url
        ini.load(filterChainDefinitions);
        Ini.Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
        // 循环Permission的url,逐个添加到section中。section就是filterChainDefinitionMap,
        // 里面的键就是链接URL,值就是存在什么条件才能访问该链接
        return section;
    }

    @Override
    public Class<?> getObjectType() {
        return getClass();
    }

    public String getFilterChainDefinitions() {
        return filterChainDefinitions;
    }

    public void setFilterChainDefinitions(String filterChainDefinitions) {
        this.filterChainDefinitions = filterChainDefinitions;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }
}
